<?php
// Xiaonei客户端库文件
require_once './xiaonei.php';    
// 类库文件
require_once './lib.php';    

$config = array();

// 应用密钥
$config['api_key'] = '你的api_key';
$config['api_secret'] = '你的api_secret';

// 您的数据库设绿
$config['db_host'] = 'localhost';       //数据库服务器地址
$config['db_user'] = 'root';            //数据库用户名
$config['db_pass'] = '';                //数据库密瞿
$config['db_name'] = 'apps';         //数据库名祿
$config['db_prefix'] = 'yk_';         //数据库名祿

// 您的应用的地址
$config['app_url'] = 'http://你自己的服务器/apps/yktest/songli/';
$config['app_app_url'] = 'http://apps.guanxi.koubei.com/你自己的应用URL/';

// 鲜花设置
$config['flowers'] = array(
  1 => '牡丹', 2 => '玫瑰', 3 => '菊花', 4 => '月季', 5 => '荷花',
  6 => '梅花', 7 => '杜鹃', 8 => '雪花', 9 => '窗花', 10 => '麻花'
  );


// 实例化Xiaonei类库
$my = new Xiaonei($config['api_key'], $config['api_secret']);

// 获取登录用户
$uid = $my->require_login();

try {
 if (!$my->api_client->users_isAppAdded()) {
      $my->redirect($my->get_add_url());
 }
}catch (Exception $ex) { 
  $my->set_user(null, null);
  $my->redirect($config['app_url']);
}

  try{
		$method="getInfo";
		$params['uids']=$uid;
		$params['fields']=array('name','birthday','tinyurl','mainurl','sex');
		$user=$my->api_client->users($method,$params);
		//print_R($user);
		
		$conn = get_db_conn();
		$sql = "SELECT * FROM `".$config['db_prefix']."users` WHERE `uid` = '$uid' ";
		$user_result = mysql_query($sql, $conn);
		if(mysql_num_rows($user_result)<1) {
			$sql2 = "INSERT INTO `".$config['db_prefix']."users` (uid, username, head, money) VALUES ('$uid', '".trim($user[0]['name'])."', '".trim($user[0]['tinyurl'])."', 0) ";
			mysql_query($sql2, $conn);
		}
  }catch(Exception $ex){		
		exit();
  }

// 获取好友信息
  try{
		$method="getFriends";
		$friends=$my->api_client->friends($method,$params);	
		//print_R($friends);
  }catch(Exception $ex){		
		exit();	
  }
 
?>

<style type="text/css">
<?php
echo file_get_contents('styles/default.css');
?>
</style>

<!-- 创建一个标准的 Xiaonei 页面头部 -->
